home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / asm32.zip / E32.ZIP / E32.ASM < prev    next >
Assembly Source File  |  1996-08-26  |  12KB  |  622 lines

  1. ; E32.ASM - Copyright (C) 1993 - 1996 Douglas Herr
  2. ;  all rights reserved
  3.  
  4. ;
  5. ; This is the main E32 source file
  6. ;
  7.  
  8. ; 03/22/1996 DH: version 1.41
  9. ;                changed F8 function from DEL EOL to LINE menu
  10. ;
  11. ; 03/29/1996 DH: version 1.42
  12. ;                LOAD function with wildcard in filename uses ASM32:MarkFile
  13. ;                instead of ASM32:PickFile
  14.  
  15. ; 08/26/1996 DH: version 1.43
  16. ;                SCROLL LOCK function supported    
  17.  
  18. include    model.inc
  19.  
  20. public    main32, quit
  21.  
  22. extrn    getcmd:near, keyifwaiting:near
  23. extrn    strchr:near, cursoron:near, qfname:near
  24. extrn    insert:near, strndup:near
  25. extrn    tprintce:near
  26. extrn    ucursoron:near
  27. extrn    htext:near
  28.  
  29. extrn    showfkey:near
  30. extrn    display_screen:near
  31. extrn    topline:near, showpos:near
  32. extrn    get_screen_data:near
  33. extrn    insert_key:near
  34. extrn    readfile:near
  35.  
  36. extrn    isalpha:near, isdigit:near
  37.  
  38. extrn    undo:near, printmenu:near, print:near, mark:near, cut:near
  39. extrn    save:near, del_eol:near, del_l:near, udel_l:near
  40. extrn    screen_rows:near, dosshell:near
  41. extrn    upcase:near, screen_columns:near, locase:near, search:near
  42. extrn    home:near, up:near, pgup:near, left:near, right:near
  43. extrn    endd:near, down:near, pgdn:near, cursoron:near, del_char:near
  44. extrn    del_eol:near, bottom:near, top:near, goto:near
  45. extrn    window_mode:near, switch:near, swapmode:near, search_again:near
  46. extrn    pushpos:near, poppos:near, replace:near, merge:near, setup:near
  47. extrn    new:near, load:near, ffeed:near, copy:near, paste:near
  48. extrn    filemenu:near, blockmenu:near, searchmenu:near, screenmenu:near
  49. extrn    gotomenu:near, linemenu:near
  50.  
  51. extrn    yesno_message:near
  52. extrn    working:near
  53. extrn    swap_files:near
  54.  
  55. ;extrn    breakrelease:near
  56. public    x0
  57.  
  58. includelib    ..\asm32cw.lib
  59.  
  60. include    dataseg.inc
  61.  
  62. breakflag    db 0
  63. public    breakflag
  64.  
  65. public    cursor, top_of_screen, filesel, filesiz, buffersiz
  66. public    cur_posn, file_row, filename, first_row, mouse_on
  67. public    normal, inverse, warning, key_status, insert_mode
  68. public    columns, rows, dirty_bits, left_margin
  69. public    screen_addr, screen_data_size, screen2_data
  70. public    save_column, count_bytes, count_start, save_row
  71. public    undo_buffer, undo_length
  72. public    push_mode, push_offset
  73. public    int24h_msg, verify_msg, extended_key, no_file_name
  74.  
  75. public    mark_mode, mark_start, mark_end, mark_home, nul
  76. public    file_data_ptr, file_data_len, number_of_files
  77. public    display_mode
  78.  
  79. extrn    window_row:byte
  80. extrn    swapmode_prompt:byte
  81.  
  82. programmer    db 0Dh,0Ah,0Dh,0Ah,' E32.EXE version 1.43',0Dh,0Ah
  83.         db ' Copyright (C) 1996 Douglas Herr',0Dh,0Ah,'$'
  84. exit_mess    db ' Quit E32 (Y/N)?',0
  85. verify_mess    db ' Lose changes (Y/N)?',0
  86. no_file_name    db '<no file name>',0
  87.  
  88. ; default colors used by GET_SCREEN_DATA
  89. public    default_normal
  90. default_normal    db 17h
  91. default_inverse    db 70h
  92. default_warning    db 0Ch
  93.  
  94. columns        dw 0
  95. rows        dw 0
  96. screen_addr    dd ?
  97. normal        db 23
  98. inverse        db 70h
  99. warning        db 0Ch
  100. screen_data_size    equ    $-columns
  101.  
  102. mouse_on    db 0
  103. key_status    db ?
  104. insert_mode    db ?
  105.  
  106. undo_buffer    dd ?
  107. undo_length    dd 0
  108. paste_buffer    dd 0        ; near pointer to paste buffer
  109. valid_keys    db 59,60,61,62,63
  110.         db 64,65,66,67,68
  111.  
  112.         db 104,105,106,107,108
  113.         db 109,110,111,112,113
  114.  
  115.         db 71,72,73,75,77
  116.         db 79,80,81,82,83
  117.  
  118.         db 115,116,117,118,132
  119.         db 99,100,101,102,103
  120.  
  121.         db 2Dh,84,86,87,88,89,91,92,97,98,93
  122. nul        dw 0,0
  123.  
  124. dispatch_table  dd offset CGROUP:undo
  125.         dd offset CGROUP:searchmenu
  126.         dd offset CGROUP:printmenu
  127.         dd offset CGROUP:blockmenu
  128.         dd offset CGROUP:gotomenu
  129.         dd offset CGROUP:screenmenu
  130.         dd offset CGROUP:filemenu
  131.         dd offset CGROUP:linemenu
  132.         dd offset del_l, offset udel_l
  133.  
  134.         dd new, screen_rows, ffeed, copy, dosshell
  135.         dd upcase, load, screen_columns, locase, search
  136.         dd home, up, pgup, left, right
  137.         dd endd, down, pgdn, cursoron, del_char
  138.  
  139.         dd word_left, word_right, del_eol, bottom, top
  140.         dd window_mode,switch, swapmode, goto, search_again
  141.  
  142.         dd quit, setup
  143.         dd offset CGROUP:print
  144.         dd offset CGROUP:mark
  145.         dd offset CGROUP:cut
  146.         dd offset CGROUP:paste
  147.         dd offset CGROUP:del_eol
  148.         dd offset CGROUP:del_l
  149.         dd pushpos, poppos, replace
  150.  
  151. drive_error    db 'Drive not ready:  retry? (Y/N)',0
  152. verify_msg    db 'Lose changes?',0
  153. int24h_msg    dd offset @curseg:drive_error
  154.         dd critical_exit
  155. sptr        dd 0        ; storage for stack ptr at read_next_key
  156. sseg        dw 0
  157.  
  158. file_data_ptr    dd filename
  159. filename    dd 0FFFFFFFFh    ; pointer to current filename
  160. filesel        dw 0FFFFh    ; selector of file buffer
  161. filesiz        dd 0        ; size of file
  162. buffersiz    dd 0        ; size of file buffer
  163. cursor        dd 0
  164. top_of_screen    dd 0
  165. left_margin    dw 0
  166. file_row    dd 1
  167. push_offset    dd 0
  168. push_mode    db 0        ; push status
  169.  
  170. save_column    db 0
  171. save_row    db 0
  172. dirty_bits    db 00100000b    ; 1xxxxxxxb = file has changed
  173.                 ; x1xxxxxxb = ??
  174.                 ; xx1xxxxxb = file name has changed
  175.                 ; xxx1xxxxb = FKey display is dirty
  176.                 ; xxxxx1xxb = current row is dirty
  177.                 ; xxxxxxx1b = screen is dirty
  178. cur_posn    dw 0100h
  179. mark_mode    db 0
  180. mark_start    dd 0
  181. mark_end    dd 0
  182. mark_home    dd 0
  183.  
  184. count_rows    db 0
  185. count_start    dd 0
  186. count_bytes    dd 0
  187. first_row    db 1        ; leave space at top for filename, etc
  188. display_mode    db 0        ; assumes ASCII file
  189. file_data_len    equ    $-filename
  190. number_of_files    equ    10
  191.  
  192.     db number_of_files*file_data_len dup(?)
  193.  
  194. screen2_data    label    dword
  195. @curseg    ends
  196.  
  197. include    codeseg.inc
  198. get_cmd_line:
  199.     push    ebp
  200.     xor    ebp,ebp
  201.  
  202. ; initialize first file buffer
  203.     xor    ebx,ebx
  204.     call    swap_files
  205.  
  206. ; get files on command line, last first
  207.     mov    ecx,number_of_files
  208. get0:    push    ecx
  209.     mov    ebx,ecx
  210.     dec    ebx        ; offset format
  211.     push    ebx        ; save parameter number
  212.     mov    eax,ebx        ; copy to EAX for GETCMD
  213.     call    getcmd
  214.     jecxz    short get1    ; skip if no parameter
  215.     call    strndup
  216.     call    qfname
  217.  
  218.     mov    edx,esi
  219.     push    esi
  220.     push    ecx
  221.     call    readfile
  222.     pop    ecx
  223.     pop    esi
  224.  
  225.     mov    edi,filename
  226.     push    ds
  227.     pop    es
  228.     cld
  229.     rep    movsb
  230.     mov    al,cl
  231.     stosb
  232.  
  233.     inc    ebp
  234.     jnc    short get1
  235.     dec    ebp
  236.     mov    edx,filename
  237.     mov    byte ptr [edx],0
  238. get1:
  239.     pop    ebx
  240.     call    swap_files
  241.     pop    ecx
  242.     loop    get0
  243.  
  244.     cmp    ebp,2
  245.     jbe    get2
  246.     mov    byte ptr swapmode_prompt,'4'
  247. get2:
  248.     pop    ebp
  249.     ret
  250.  
  251. ;
  252. ; program starts here
  253. ;
  254. main32:
  255.  
  256. ; lock program code and data
  257.  
  258.     mov    bx,cs
  259.     sys    GetSelDet32
  260.     mov    esi,edx
  261.     mov    ebx,ecx
  262.     sys    LockMem32
  263.  
  264. ; initialize file data areas
  265.     push    ds
  266.     pop    es
  267.     cld
  268.     lea    esi,filename        ; -> 1st file data record
  269.     mov    edx,file_data_len    ; bytes per file data record
  270.     mov    edi,esi
  271.     mov    ecx,number_of_files-1    ; # to copy
  272.     add    edi,edx            ; -> 2nd file data record
  273. m0:
  274.     push    esi            ; save ptr
  275.     push    ecx            ; save count
  276.     mov    ecx,edx            ; bytes to copy
  277.     rep    movsb
  278.     pop    ecx            ; count
  279.     pop    esi            ; ptr
  280.     loop    m0            ; do all
  281.  
  282.     call    get_screen_data
  283.     cli
  284.     mov    sseg,ss
  285.     mov    sptr,esp
  286.     sti
  287.  
  288. ; set INT 24h address
  289.     mov    cx,cs
  290.     lea    edx,int24h
  291.     mov    bl,24h
  292.     sys    SetVect
  293.  
  294. ; turn insert key toggle on
  295.     mov    ax,1
  296.     call    insert
  297.  
  298. ; get command line input
  299.     call    get_cmd_line
  300.  
  301. ; create undo buffer
  302.     mov    ebx,128
  303.     sys    GetMemNear
  304.     mov    undo_buffer,esi
  305.     jmp    short read_next_key
  306.  
  307. critical_exit:
  308.     cli
  309.     mov    ss,sseg
  310.     mov    esp,sptr
  311.     sti
  312.  
  313. read_next_key:
  314.     call    showpos
  315.     mov    fs,filesel
  316.     cmp    mark_mode,0    ; is the mark state on?
  317.     je    short mark_off    ; if not, skip this
  318.     or    dirty_bits,4    ; refresh the current row
  319.     mov    dx,cur_posn
  320.     cmp    save_row,dh    ; are we on the same row?
  321.     je    short same_row    ; yup, redo the row only
  322.     or    dirty_bits,1    ; refresh the whole screen
  323.     and    dirty_bits,(NOT 4)    ; cancel refresh row request
  324. same_row:
  325.     mov    eax,cursor    ; get cursor position
  326.     mov    ebx,mark_home    ; get the anchor mark position
  327.     cmp    eax,ebx        ; moving backward in file?
  328.     ja    short s1    ;  no: update mark_end & mark_start
  329.     xchg    eax,ebx        ; switch start and end position
  330. s1:    mov    mark_end,eax    ; store start and end marks
  331.     mov    mark_start,ebx
  332. mark_off:
  333.     mov    dx,cur_posn
  334.     mov    save_row,dh
  335.     call    cursoron
  336.     test    dirty_bits,4 or 1    ; need screen update?
  337.     jz    short check_shift_keys
  338.     call    display_screen
  339.  
  340. check_shift_keys:
  341.     call    capslock
  342.     shr    mouse_on+1,1
  343.     jnc    short s2
  344.     jmp    read_next_key
  345. s2:    call    keyifwaiting
  346.     jnc    short process_key
  347.     call    topline
  348.     jmp    check_shift_keys
  349.  
  350. process_key:
  351. ; turn mouse cursor off if it is on
  352.     shr    mouse_on,1
  353.     jnc    short key0
  354.     push    eax
  355.     mov    ax,2
  356.     int    33h
  357.     pop    eax
  358. key0:
  359.     shr    ah,1
  360.     jnc    short normal_key
  361.     call    extended_key
  362.     jc    short exit
  363.     jmp    read_next_key
  364.  
  365. normal_key:
  366.     cmp    al,08h            ; backspace?
  367.     jne    short normal1
  368.     cmp    cursor,0        ; start of file?
  369.     je    read_next_key        ;  yup, no backspace
  370.     call    left
  371.     call    del_char
  372.     jmp    read_next_key
  373. normal1:
  374.     call    insert_key
  375.     jmp    read_next_key
  376. x0:
  377. exit:
  378.  
  379. ; reset mouse
  380.     xor    ax,ax
  381.     int    33h
  382.  
  383. ; display programmer info
  384.     lea    edx,programmer
  385.     mov    ah,9
  386.     int    21h
  387.  
  388. ; byebye
  389.     mov    ax,4C00h
  390.     int    21h
  391.  
  392. subroutines    proc    near
  393.  
  394. ;
  395. ; process extended key code
  396. ;
  397. extended_key:
  398.     lea    ebx,valid_keys
  399.     call    strchr
  400.     jc    short bad_key
  401.     push    ds
  402.     pop    es
  403.     jmp    dispatch_table[eax*4]
  404.  
  405. bad_key:
  406.     clc
  407.     ret
  408.  
  409. ;
  410. ; check status of CAPSLOCK, SHIFT, CTRL, ALT keys
  411. ;
  412. capslock:
  413.     mov    ax,0200h
  414.     int    16h        ; get key toggle status byte
  415.     mov    ah,al
  416.     and    ah,80h        ; isolate INSERT status
  417.     mov    insert_mode,ah
  418.  
  419.     cmp    key_status,al    ; compare with previous and update
  420.     mov    key_status,al    ; ZF = 1 if no changes
  421.     jnz    showfkey    ; update prompt line if changed
  422.     ret
  423.  
  424.  
  425. ;
  426. ; move cursor one word right
  427. ;
  428. word_right:
  429. ;
  430. ; move to end of current word
  431. ; exit when non-AlphaNum character found
  432. ;
  433. word_end_right:
  434.     push    fs
  435.     pop    es
  436.     mov    esi,cursor
  437.     cmp    esi,filesiz
  438.     jae    short wer9
  439.     movzx    ax,byte ptr es:[esi]
  440.     call    isalphanumber
  441.     jc    short wer9
  442.     call    right
  443.     jmp    word_end_right
  444. wer9:
  445.  
  446.  
  447. ;
  448. ; skip spaces if starting from a space character
  449. ;
  450. strip_space_right:
  451.     push    fs
  452.     pop    es
  453.     mov    esi,cursor
  454.     cmp    esi,filesiz
  455.     jae    short ssr9
  456.     movzx    ax,byte ptr es:[esi]
  457.     call    isalphanumber
  458.     jnc    short ssr9        ; exit if Digit
  459.     call    right            ; go to previous character
  460.     jmp    strip_space_right
  461. ssr9:
  462.     clc
  463.     ret
  464.  
  465.  
  466. ;
  467. ; move cursor one word left
  468. ;
  469. word_left:
  470. ;
  471. ; skip spaces if starting from a space character
  472. ;
  473. strip_space_left:
  474.     push    fs
  475.     pop    es
  476.     mov    esi,cursor
  477.     test    esi,esi
  478.     jz    short ssl9        ; done if at start of file
  479.  
  480.     movzx    ax,byte ptr es:[esi-1]
  481.     call    isalphanumber
  482.     jnc    short ssl9        ; exit if Digit
  483.     call    left            ; go to previous character
  484.     jmp    strip_space_left
  485. ssl9:
  486.  
  487. ;
  488. ; go to start of current word
  489. ; scan off alpha and digit characters
  490. ; moving left
  491. ;
  492. word_start_left:
  493.     push    fs
  494.     pop    es
  495.     mov    esi,cursor
  496.     test    esi,esi
  497.     jz    short wsl9        ; done if at start of file
  498.  
  499.     movzx    ax,byte ptr es:[esi-1]
  500.     call    isalphanumber
  501.     jc    short wsl9        ; continue if digit
  502.     call    left
  503.     jmp    word_start_left
  504. wsl9:
  505.     clc
  506.     ret
  507.  
  508. isalphanumber:
  509.     call    isalpha
  510.     jc    isdigit
  511.     ret
  512.  
  513.  
  514. ;
  515. ; INT 24h management
  516. ;
  517. int24h:
  518.     sti                ; Enable interrupts
  519.     pushf                ; Push flags
  520.     pushad
  521.     push    ds
  522.     push    es
  523.     mov    ax,_NEAR
  524.     mov    ds,ax
  525.     mov    es,ax
  526.     mov    esi,int24h_msg
  527.     mov    ah,warning
  528.     call    yesno_message
  529.     cmp    al,'Y'
  530.     je    short int24exit
  531.     jmp    int24h_msg+4
  532.  
  533. int24exit:
  534.     call    working
  535.     pop    es
  536.     pop    ds
  537.     popad
  538.     popf                ; Pop flags
  539.     mov    al,1
  540.     iretd                ; Interrupt return
  541.  
  542. ;
  543. ; exit E32, checking for unsaved changes
  544. ;
  545. quit:
  546.     push    dword ptr window_row
  547.     mov    window_row,1
  548.     or    dirty_bits,00010000b    ; force redo of F-key prompts
  549.  
  550. ; check hidden file data areas for unsaved files
  551. q0:    mov    ecx,number_of_files
  552. q1:    push    ecx
  553.  
  554.     mov    ebx,ecx
  555.     dec    ebx
  556.     jnz    short q1a        ; skip if not last file
  557.     mov    ebx,number_of_files    ; else retrieve initial file
  558.     dec    ebx
  559. q1a:
  560.     call    swap_files        ; get file data
  561.     test    dirty_bits,10000000b    ; continue if not changed
  562.     jz    short q2
  563.     call    display_screen
  564.     mov    ah,warning
  565.     mov    esi,offset verify_mess
  566.     call    yesno_message
  567.     cmp    al,'Y'            ; is the answer YES?
  568.     je    short q2        ; yup, check next file
  569.     pop    ecx
  570.     jmp    short dont_exit
  571.  
  572. q2:    pop    ecx
  573.     loop    q1
  574.  
  575.     lea    esi,exit_mess        ; prompt for 'EXIT'
  576.     mov    ah,inverse
  577.     call    yesno_message
  578.     cmp    al,'Y'            ; is the answer YES?
  579.     jne    short dont_exit
  580.  
  581.     cmp    columns,90    ; in RamFont mode?
  582.     jne    short exit100
  583.     call    htext
  584. exit100:
  585.     pop    dword ptr window_row
  586.  
  587. ; clear last row
  588.     mov    dh,byte ptr rows
  589.     xor    dl,dl
  590.     call    ucursoron
  591.     inc    dh
  592.     lea    esi,nul
  593.     mov    ah,normal
  594.     call    tprintce
  595.     stc                ; exit flag
  596.     ret
  597.  
  598. dont_exit:
  599.     pop    dword ptr window_row
  600.     clc                ; no exit flag
  601.     ret
  602.  
  603. ;
  604. ; PRINT_MSG
  605. ; print message at [ESI] on last row of screen
  606. ;
  607.  
  608. public    print_msg
  609.  
  610. print_msg:
  611.     mov    ah,inverse
  612.     mov    dh,byte ptr rows
  613.     inc    dh
  614.     xor    dl,dl
  615.     call    tprintce
  616.     ret
  617.  
  618. subroutines    endp
  619.  
  620. @curseg    ends
  621.     end
  622.